

const axios = require('axios');
const fs = require('fs');


const testUrl = 'https://oapi.dingtalk.com/robot/send?access_token=07f57152996648b04a2e3d41edf7b10ef333c65e558eae992033620ef5cefa2d';  // v5

let ddArr = [
  testUrl,
];

let ios_data = fs.readFileSync('/tmp/upload_ios.txt', 'utf8');
let env = fs.readFileSync('/tmp/env.txt', 'utf8');

let downUrl, updateDesc, QRUrl, OS;

if(ios_data){
    let pData = JSON.parse(ios_data);
    if(pData.code == 0){
        let dd = pData.data;
        downUrl = `https://www.pgyer.com/${dd.appKey}`;
        updateDesc = dd.appUpdateDescription;
        OS = dd.appType == 1 ? "iOS": '安卓';
        QRUrl = dd.appQRCodeURL;

        for(let i = 0; i< ddArr.length; i++){
            let url = ddArr[i];
            sendDing(OS, updateDesc, downUrl, QRUrl, url)
        }
    }else{
        console.log('----打包失败----');
        console.log(android_data);
    }
}

function sendDing(OS, updateDesc, downUrl, QRUrl, dingUrl) {
    let ddd = {
        "msgtype": "markdown",
        "markdown": {"title":"应用打包更新",
            "text": `# ${OS}新包发布 \n \n > 服务器环境: ${env} \n \n > 更新内容: \n\n ${updateDesc} \n\n > 下载地址: [${downUrl}](${downUrl}) \n\n > 扫码直接下载: \n ![](${QRUrl})`
        }
    };
    axios({
        method: 'post',
        url: dingUrl,
        data: ddd
    }).then(function(response) {
        console.log(response.data);
    });
}




